HTML5 Responsive Notify Support Product Page

Solved

Hallo, how I can call the script only when a variable is set?

Reported 11 years ago
1
has this problem
11 years ago Carmen Scheibe posted:
Hallo, how I can call the script only when a variable is set.

<script type="text/javascript">
if (document.URL.indexOf('Var') != -1){

body.on.onload= "dmxNotifyAction({&quot;msg&quot;: &quot;Artikel erfolgreich hinzugef&uuml;gt. &quot;, &quot;extendedTimeOut&quot;: 2000, &quot;tapToDismiss&quot;: false})"

}</script>


does not work

Replies

Replied 11 years ago
11 years ago Miroslav Zografski replied:
Hello Carmen,

You like to display notification based on a certain URL variable ?

Regards.
Replied 11 years ago
11 years ago Carmen Scheibe replied:
Yes, that exactly I want do.
Replied 11 years ago
11 years ago Miroslav Zografski replied:
Hello Carmen,

First you need to get the URL Variable. That you can do using following function:
	function getUrlVars() {
		var vars = {};
		var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
			vars[key] = value;
		});
		return vars;
	}

and retrieve then the variable in following fashion:
var myVariable= getUrlVars()["URLVarName"];

Then you can check if that variable is set and is not empty and if so execute the dmxNotifyAction function with the requested arguments:
if(myVariable && myVariable!= ''){
    dmxNotifyAction({"msg": "Your Message here", "extendedTimeOut": 2000, "tapToDismiss": false});
}

Your full code will be:
<script>
function getUrlVars() {
		var vars = {};
		var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
			vars[key] = value;
		});
		return vars;
	}

var myVariable = getUrlVars()["alabala"];
if(myVariable){
	dmxNotifyAction({"msg": "Your Message here", "extendedTimeOut": 2000, "tapToDismiss": false});
}
</script>

And must be placed right before the body closing tag in your page.
Also you must check if following scripts are available in your head already:
<link rel="stylesheet" type="text/css" href="Styles/dmxNotify.css" />
<script type="text/javascript" src="ScriptLibrary/jquery-latest.pack.js"></script>
<script type="text/javascript" src="ScriptLibrary/dmxNotify.js"></script>
<script>
function dmxNotifyAction() {   //ver 1.00
  if (arguments && arguments.length > 0) {
    if(typeof arguments[0] == 'object'){
      jQuery.dmxNotify(arguments[0]);
    }else if(arguments[0] === 'closeAll'){
       jQuery.dmxNotify.closeAll();
    }
  }
}
</script>

If those are not present in the page create a link and apply to it dmxNotify, so it could place those scripts in the page, and then remove the link.

Regards.
Replied 11 years ago
11 years ago Carmen Scheibe replied:
Thank you so much. This works great. This is a really useful extension.
Replied 11 years ago
11 years ago Miroslav Zografski replied:
You are welcome Carmen.

Regards.

Reply to this topic