Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts

Saturday, March 26, 2011

Unsafe JavaScript attempt to access frame with URL

Getting a "Unsafe JavaScript attempt to access frame with URL" message in Chrome when trying something dodgy across domains or subdomains with iframes?

It is pretty much a browser security feature. So there's no way it is going to work.

Eventually I settled for doing everything from within an iframe.

Sunday, March 13, 2011

ReplaceAll in Javascript Example

ReplaceAll in Javascript Example:

Instead of:

mynicestring = mynicestring.replace("find","replacement");

Use:

mynicestring = mynicestring.replace(/find/g,"replacement");

Wednesday, March 02, 2011

jQuery modal not working when inside click function

It seems that every time I want to do something new, I am faced with learning/figuring out a new library or technology. This time it was jQuery and boy I was having some problems with it.

One of the issues I was facing was with this code, where I wanted to show a modal 'pop up' when an image was clicked. The 'modal' command worked fine, except that it refused to work when called from inside a 'click' function.

If anyone knows how to make this work I'd love to know.

//works on its own
jQuery('#takeidphoto').modal({position: [160,160]});

//totally doesn't work
jQuery('#takephotoimg').click(function() {
jQuery('#takeidphoto').modal({position: [160,160]});
});


In the end I resorted to plain old javascript and used this decent library from Matt Kruse called 'DIV Popups' which served my purpose: http://www.javascripttoolbox.com/lib/popup/example.php

Sunday, January 27, 2008

How to dynamically change the height of an IFRAME in both Firefox and IE

Based on various code snippets that I found on the Internet, here is how to do it:

(Please contact me if you are the original author of the functions)



function getDocHeight(doc) {
var docHt = 0, sh, oh;
if (doc.height) {
docHt = doc.height;
}
else if (doc.body) {

if (doc.body.scrollHeight) docHt = sh = doc.body.scrollHeight;

if (doc.body.offsetHeight) docHt = oh = doc.body.offsetHeight;

if (sh && oh) docHt = Math.max(sh, oh);
}

return docHt;
}

function fnResizeIframe(sIFrameName) {

var iframeWin = window.frames[sIFrameName];

var iframeEl = window.document.getElementById? window.document.getElementById(sIFrameName): document.all? document.all[sIFrameName]: null;

if ( iframeEl && iframeWin ) {
iframeEl.style.height = "auto";
var docHt = getDocHeight(iframeWin.document);

if (docHt) iframeEl.style.height = docHt + "px";

}
else { //firefox
var docHt = window.document.getElementById(iframeName).contentDocument.height;
window.document.getElementById(iframeName).style.height = docHt + "px";
}


} //end of function getDocHeight(doc)



Thursday, August 17, 2006

Hiding all Checkboxes on a HTML Page with Javascript

Iterating through all the checkbox elements on a page using the javascript getElementsByTagName() command.

var inputs = window.document.getElementsByTagName('input');

for(var i=0; i < inputs.length; i++){ //iterate through all input elements
if (inputs[i].type.toLowerCase() == 'checkbox') { //if the element is a checkbox
inputs[i].style.display = "none";
}
}