书签需要Javascript帮助

Javascript help needed with bookmark

本文关键字:帮助 Javascript 书签      更新时间:2023-09-26

嘿,我有这个小javascript书签

javascript:(function(){ window.open('http://www.mywebsite.com/index.php?currentsite#bookmark'); })()

如何将当前网站的网址放入该网址中?我听说过使用document.URL但我不确定如何将其与当前浏览的网站的URL一起放入书签中的URL。这意味着目前的结果是http://www.mywebsite.com/index.php?currentsite=document.URL#bookmark

谢谢

javascript:(function(){ window.open('http://www.mywebsite.com/index.php?currentsite=' + encodeURIComponent(location.href) + '#bookmark'); })()

试试window.location or document.location.href or window.location.href我忘了哪一个有效:)

尝试改用这个:

javascript:( function(){window.open('http://www.mywebsite.com/index.php?'+document.location.href+'#bookmark');} )()

只需使用 window.location.href - 像这样:

window.open( 'http://<someurl>?' + window.location.href + '#somebookmark' );

window.location.href 会给你当前帧的 href。

我不确定你在说什么,但如果你想获取完整的 URL 和 anker,你可以document.location.href http://www.w3schools.com/jsref/prop_doc_url.asp

您可以使用位置对象访问 URL 的各个部分 http://www.w3schools.com/jsref/obj_location.asp

您的代码应如下所示:

function(){ 
    var url = document.location.href;
    window.open('http://www.mywebsite.com/index.php?currentsite = ' + url); 
}

不确定这是否是你试图做的事情。