0

Inside my JavaScript I have the following variable:

url = A + 'abc/' + B + '.test';

A & B are the variables. when I am doing alert(url); I am getting the correct URL. I want to pass this url variable in the object.

<object style="width:100%; height:100%;" data="(URL as variable)"></object>
  1. How should I pass the URL as variable?
  2. Is it possible to call javaScript function on data="someFun()" ?

    function someFun(){
       url = A + 'abc/' + D + '.test';
    }
    

and then

<object style="width:100%; height:100%;" data="someFun()"></object>
  1. If yes, which approach is better passing variable or calling a function in case of URL ?

1 Answer 1

2

The JavaScript cannot get executed inside data=. So you might need to use:

element.setAttribute("data", url);

After the url variable is declared.

To call a function on data="someFun()", you need to select using:

document.querySelectorAll('[data="someFun()"]')[0];
Sign up to request clarification or add additional context in comments.

2 Comments

There is no way to pass javascript variable inside the data="<variable>" correct ? I am using object to append/load the result of url in the div like : $("#result").html('<object style="width:100%; height:100%;" data="url"></object>');
Do that data="' + url + '"></object>' way!

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.