最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to prevent execution of javascript from a browser's address bar? - Stack Overflow

programmeradmin6浏览0评论

If I go to this page and then delete the url from my browser's address bar, and then enter

javascript:document.getElementById('rsidebar').value='dsf';

The whole part refreshes. How can I prevent a page from refreshing when executing javascript from the address bar?

Also, are there any other techniques to manipulate a page without having access to the page source like the above method?

If I go to this page and then delete the url from my browser's address bar, and then enter

javascript:document.getElementById('rsidebar').value='dsf';

The whole part refreshes. How can I prevent a page from refreshing when executing javascript from the address bar?

Also, are there any other techniques to manipulate a page without having access to the page source like the above method?

Share Improve this question edited Aug 18, 2014 at 12:39 Sam 7,39816 gold badges47 silver badges68 bronze badges asked Aug 18, 2009 at 14:18 comettacometta 35.7k84 gold badges220 silver badges329 bronze badges
Add a comment  | 

4 Answers 4

Reset to default 10

No, you cannot stop the user from manipulating the DOM.

You don't need to worry about people manipulating the DOM from the client-side. These changes only effect their local experience. They aren't actually affecting your site for other users.

You can easily manipulate the DOM using tools like Firebug, IEDeveloperToolbar, or Greasemonkey (Javascript engine).

  1. When you do javascript:stuff(); and stuff() produces a return value, the whole page is replaced by it. You can prevent that by using javascript:void(stuff()); or javascript:stuff();void(0);
  2. Already answered by others :)

For Q1: I think this isn't possible because the browser runs every website in its own 'sandbox'

For Q2: I believe Firebug will let you execute javascript on any webpage...

Question 1: As the earlier responders said, nothing you can do I don't think.

Question 2: Check out bookmarklets, some very cool things can be done by running your own JavaScript against pages from various sites. People have written bookmarklets to highlight things on the page, put warning indicators next to links that will open in a new window, or go to aPDF, etc.

发布评论

评论列表(0)

  1. 暂无评论