0

i googled and searched here to but unable to figure it out my script is not working

i'm loading a html file using .load function file loaded successfully but javascirpt in is not working when i view that file in browser all works..

below function is loading html file

function loadPage(page, pageElement) {

$(pageElement).load('pages/page' + page + '.html');

//loadRegions(page, pageElement);}

this is the function in ajax loaded html file

addLoadEvent(load1);

script is generated by pdftohtml script that generate canvas... i can't attach it to any event like click .. can it work as it is...

pdftohtml generate script

function adjustCharSpacing(el,actualWidth) {
    var rawWidth=el.offsetWidth;
    if(actualWidth>20 & rawWidth!=actualWidth && actualWidth>rawWidth){
        var spacing= 0;
        var s=spacing+'px';
        el.style.charSpacing = s;
        rawWidth=el.offsetWidth;

        var diff=rawWidth-actualWidth;
        if(diff20 && actualWidth>rawWidth && rawWidth!=actualWidth & el.textContent.search(' ') > -1){
        var spacing= 0;
        var s=spacing+'px';
        el.style.wordSpacing = s;
        rawWidth=el.offsetWidth;

        var diff=rawWidth-actualWidth;
        if(diff12 & rawWidth>5 & rawWidth!=actualWidth){
        if(rawWidth>actualWidth){
            while (rawWidth>actualWidth & lastRawWidth!=rawWidth){
                pixelSize--;
                el.style.fontSize = pixelSize+'px';
                lastRawWidth=rawWidth;
                rawWidth=el.offsetWidth;
            }
            var lastDiff=lastRawWidth-actualWidth;
            var nextDiff=actualWidth-rawWidth;
            if(lastDiff5)
            el.style.fontSize = pixelSize+'px';
        else
            el.style.fontSize = rawFontSize+'px';

        if(pixelSize!=el.style.fontSize){
            adjustCharSpacing(el,actualWidth);
            adjustWordSpacing(el,actualWidth);
        }

    }
}

var pdf;
function M(a,b){pdf.moveTo(a,b);}
function L(a,b){pdf.lineTo(a,b);}
function C(a,b,c,d,e,f){pdf.bezierCurveTo(a,b,c,d,e,f);}
function Q(a,b,c,d){pdf.quadraticCurveTo(a,b,c,d);}
function BP(){pdf.beginPath();}
function CP(){pdf.closePath();}
function LW(a){pdf.lineWidth=a;}
function LC(a){pdf.lineCap=a;}
function LJ(a){pdf.lineJoin=a;}
function ML(a){pdf.miterLimit=a;}
function SS(a){pdf.strokeStyle=a;}
function ST(){pdf.stroke();}
function GA(a){pdf.globalAlpha=a;}
function FS(a){pdf.fillStyle=a;}
function FI(){pdf.fill();}
function CL(){pdf.clip();}
function SV(){pdf.save();}
function RS(){pdf.restore();}

var loaded1 = false;
var assetsLoaded1 = 0;
var assetCount1 = 20;
var images1 = new Array();
var imageCount1 = 20;
function load1(){
    if (!loaded1) {
        loaded1=true;
        document.getElementsByClassName("l1")[0].innerHTML = "Loading Assets...";
        for (var i = 1; i 

1 Answer 1

1

use the callback function of load() method:

$(pageElement).load('pages/page' + page + '.html',function(){
    $('#myCanvas').on('click',function(){alert('canvas clicked');});
});

Or use delegation, e.g:

$(document.body).on('click','myCanvas', function(){
    alert('canvas clicked');
});
Sign up to request clarification or add additional context in comments.

8 Comments

Might want to show actually calling the addLoadEvent function.
how this will call addLoadEvent(load1) load1 is function specific to each html file i will be loading hundred of html files... using loadPage function ...
i want it without clicking anywhere or element ... i want to call function loadPage and function inside ajax loaded html can work auto ?
@roasted i added the script that is generated by pdftohtml files that i'm loading .. and i used your script but still its not working for me .. i don't know all functions in ajax loade files executed or not ..
if i run the file from same tab and go back to page that is loading it using ajax it works ...than i refresh i stops working why its happening ?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.