php – 在javascript中制作书签

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – 在javascript中制作书签脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试为我的网站制作一个书签.

我发了一个PHP页面,当发送GET例如www.websITe.COM/index.htML?a=banana时,它会返回echo’stand’;

现在我正在尝试制作一个书签,当我按下它时:
PHP页面执行GET操作,然后在3秒后消失的小弹出窗口中显示回显给用户的任何内容.

怎样才能做到一点

InstapaPEr Bookmarklet做到了……

javascript:
function%20iPRl5(){
  VAR%20d=document,z=d.createElement('scr'+'ipt'),b=d.body,l=d.location;
  try{
    if(!b)
      throw(0);
    d.title='(Saving...)%20'+d.title;
    z.setattribute('src',l.protocol+'//www.instapaper.com/j/deyNbbpjuSei?u='+encodeURIcomponent(l.href)+'&t='+(new%20Date().getTime()));
    b.appendChild(z);
  }
  catch(e){
    alert('Please%20wait%20until%20the%20page%20has%20loaded.');
  }
}
iprl5();
void(0)

解决方法

bookmarklet是一段javascript,它运行在您所在页面的范围内.

它并不意味着只调用任意网址而不能这样做,因为这会违反相同的原始实践.如果您的PHP可以返回JSONP,那么您可以编写一个bookmarklet,它将在页面上插入一个脚本,该脚本会调用您返回的脚本 – 这样也可以显示一个弹出窗口

javascript:
function%20iprl5(){
  var%20d=document; // shorten document object
  var z=d.createElement('scr'+'ipt'); // create a script tag
  var b=d.body; // get document.body
  var l=d.location; // get document.location - I would get document.URL instead
  try{
    if(!b) throw(0); // if there is no body object available
    d.title='(Saving...)%20'+d.title; // set document.title
    z.setAttribute('src',l.protocol+'//www.yourserver.com/test.PHP?u='+encodeURIComponent(l.href)+'&time='+(new%20Date().getTime())); // create the script url
    b.appendChild(z); // append it to the body - I would append to head myself
  }
  catch(e){ // give an error
    alert('Please%20wait%20until%20the%20page%20has%20loaded.');
  }
}
iprl5(); // call it
void(0); // make sure it does not return a value to the window

将此视图:http://www.instapaper.com/j/deyNbbpjuSei?u = http://www.stackoverflow.com粘贴到位置栏中,查看作为您所在页面的一部分返回的内容

脚本宝典总结

以上是脚本宝典为你收集整理的php – 在javascript中制作书签全部内容,希望文章能够帮你解决php – 在javascript中制作书签所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。