问题描述
我需要获取当前URL的URL片段并将片段(哈希)放入php变量。像这样:
//creating array of report struct
var currentReport = [report]()
//currentReport.append(report(question:questions,AnswersChosen:[String](),userCount:0))
//array for what users are selecting
answerChosen.append(sender.title(for: .normal)!)
//print (answerChosen)
//currentReport.AnswersChosen = answerChosen
print(answerChosen)
//counting number of times wrong button is pressed
ActionCount += 1
//currentReport.userCount = ActionCount
print(ActionCount)
currentReport.append(report(question:questions[currentQuestion],AnswersChosen:answerChosen,userCount:ActionCount))
print(currentReport)
当我在$current_url = exec(phantomjs script.js);
文件中使用window.location.href
时,它显示script.js url。
我需要获取php文件的当前URL,而该文件是fragment(hash)。
我该怎么做。请帮忙。
更新: 我需要获取像phantomjs这样执行的当前php文件的URL:examle.com/need_url_of_this_page.php#11111
解决方法
不确定您要问的是什么,但我想这是您的script.js
中的问题:
var webPage = require('webpage');
var page = webPage.create();
page.open('http://phantomjs.org',function (status) {
var url = page.url;
console.log('URL: ' + url);
phantom.exit();
});