Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > OS X > OS X 10.8 Mountain Lion

Reply
 
Thread Tools Search this Thread Display Modes
Old Nov 27, 2012, 08:03 AM   #1
nelly22
macrumors regular
 
Join Date: Sep 2009
Safari JavaScript loading

In Safari when JavaScripts is turned from off to on, it loads js in all tabs in all windows.

Is there any extension/plugin/... which loads js only in current tab or only in new tabs?
nelly22 is offline   0 Reply With Quote
Old Nov 27, 2012, 09:57 AM   #2
GGJstudios
macrumors Westmere
 
Join Date: May 2008
Quote:
Originally Posted by nelly22 View Post
In Safari when JavaScripts is turned from off to on, it loads js in all tabs in all windows.

Is there any extension/plugin/... which loads js only in current tab or only in new tabs?
You didn't mention what version of Safari you're using, but in Safari 5, if you have JavaScript disabled when you visit a page, then enable JavaScript, it does not load any JavaScript until you refresh the page or go to a new page. That behavior may or may not have changed with Safari 6. I use JavaScript Blocker to manage JavaScript on sites I visit.
GGJstudios is offline   0 Reply With Quote
Old Nov 27, 2012, 10:06 AM   #3
wrldwzrd89
macrumors G4
 
wrldwzrd89's Avatar
 
Join Date: Jun 2003
Location: Solon, OH
A quick Google search doesn't find anything particularly informative.

However, creating a Safari extension to achieve this end should not be that hard.

This little bit of JavaScript will fetch the particular tab that is active (note that this only works in the context of a Safari Extension):
Code:
safari.application.activeBrowserWindow.activeTab
Combining that with a block content startup script, like this 2-part one:
Code:
function isItOkay() {
    var myMessageData = event.url;
    var theAnswer = safari.self.tab.canLoad(event, myMessageData);
    if (theAnswer == "block") {
        event.preventDefault();
    }
}
 
document.addEventListener("beforeload", isItOkay, true);

function blockOrAllow(event) {
    if (event.name === "canLoad") {
        var itsAnAd = event.message.match(/ads.example.com/i);
        if (itsAnAd) {
            event.message = "block";
        }
        else {
            event.message = "allow";
        }
    }
}
 
safari.application.addEventListener("message", blockOrAllow, true);
...and modifying the code accordingly to intercept and stop JS in inactive tabs from running. If you're not a coder like me, I wouldn't be surprised if you don't understand anything I posted. That's okay, though - I do, and I'd be willing to help address a need that I am sure others besides you are looking for.
__________________
iMac Intel (Rev H, 27"), 1TB HDD, 16GB RAM, 10.8.4
wrldwzrd89 is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > OS X > OS X 10.8 Mountain Lion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Is there a way to disable javascript only for certain sites in safari? christarp OS X Mavericks (10.9) 2 Feb 26, 2014 11:05 PM
JavaScript Slow Loading SandboxGeneral Site and Forum Feedback 6 Mar 9, 2013 01:17 PM
Cannot turn off Javascript in Safari pribl iPhone Tips, Help and Troubleshooting 1 Jan 17, 2013 05:11 PM
Resolved: Web browsing, Safari and Javascript cyberghoser1 PowerPC Macs 24 Jan 4, 2013 12:23 PM
Safari 6.0.2 and javascript Franciturci OS X 10.8 Mountain Lion 2 Nov 16, 2012 09:32 AM

Forum Jump

All times are GMT -5. The time now is 06:50 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC